<%@ page language="java" contentType="text/html; charset=UTF-8"	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="perm" uri="/WEB-INF/tld/perm.tld"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<html>
	<script>var ctx="${ctx}";</script>
	<head>
	    <meta charset="utf-8">
	    <meta name="viewport" content="width=device-width, initial-scale=1.0">
	    <title>新品发布管理</title>
	    <meta name="keywords" content="体验,友好,高级管理台,易用,高性能,高扩展性,bootstrap框架,响应式后台">
	    <meta name="description" content="这是一个完全响应式，基于Bootstrap3最新版本开发的扁平化主题，她采用了主流的左右两栏式布局，使用了Html5+CSS3等现代技术">
	    <meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="Cache-Control" content="no-cache, must-revalidate">
		<meta http-equiv="expires" content="Wed, 26 Feb 209908:21:57 GMT"> 
	    
		<link rel="shortcut icon" href="favicon.ico"> 
		<link href="${ctx}/static/css/bootstrap.min.css?v=${static_version}/" rel="stylesheet">
		<link href="${ctx}/static/css/font-awesome.min.css?v=4.4.0?v=${static_version}/" rel="stylesheet">
		<link href="${ctx}/static/css/plugins/footable/footable.core.css?v=${static_version}/" rel="stylesheet">
		<link href="${ctx}/static/css/plugins/summernote/summernote.css?v=${static_version}/" rel="stylesheet">
		<link href="${ctx}/static/css/plugins/summernote/summernote-bs3.css?v=${static_version}/" rel="stylesheet">
		<link href="${ctx}/static/plugins/laypage/laypage.css?v=${static_version}"  rel="stylesheet">
		<link href="${ctx}/static/css/plugins/iCheck/custom.css?v=${static_version}/" rel="stylesheet">
		<link href="${ctx}/static/css/plugins/chosen/chosen.css?v=${static_version}/" rel="stylesheet">
		<link href="${ctx}/static/css/animate.min.css?v=${static_version}/" rel="stylesheet">
		<link href="${ctx}/static/js/plugins/layer/laydate/laydate.css?v=${static_version}/" rel="stylesheet">
		<link href="${ctx}/static/css/plugins/webuploader/webuploader.css?v=${static_version}/" rel="stylesheet">
		<link href="${ctx}/static/css/style.min.css?v=${static_version}/" rel="stylesheet">
		<link href="${ctx}/static/css/plugins/switchery/switchery.css?v=${static_version}/" rel="stylesheet">
		<link href="${ctx}/static/js/plugins/uploadify/uploadify.css?v=${static_version}/" rel="stylesheet">
	    
	</head>
	<body class="gray-bg">
    	<div class="ibox float-e-margins">
    		<div class="ibox-content">
                <form class="form-group" id="newgoods_table_form">	
                	<input type="hidden" name="orderBy" value="create_date desc">
                	<input type="hidden" id="brand-select-id" name="brandId" value="">
                	<input type="hidden" id="cat-select-id" name="catId" value="">
                	<div class="row">
                		<perm:hasPermission code="newgoods/find">
                        <div class="col-md-2"><input name="keyword" type="text" placeholder="请输入关键字" class="form-control" /></div>
		     	  		<div class="col-md-4">
                            <div class="input-daterange input-group">
                                <input id="startTime" type="text" class="input-md form-control layer-date" placeholder="开始时间"  name="startTime">
					        	<span class="input-group-addon">至</span>
					        	<input id="endTime" type="text" class="input-md form-control layer-date" placeholder="结束时间"  name="endTime">
                            </div>
						</div>
						<div class="col-md-2 col-sm-2">
							<select data-placeholder="选择商品类型" id="cat-select-select" class="input-md form-control chosen-select" tabindex="4">
			                    <option value="">选所商品分类</option>
			                </select>
						</div>
						<div class="col-md-2 col-sm-2">
							<select data-placeholder="选择商品类型" id="brand-select-select" class="input-md form-control chosen-select" tabindex="4">
			                    <option value="">选所商品类型</option>
			                </select>
					    </div>
						<div class="col-md-1 col-sm-2">
							<button id="newgoods_table_search" type="button" class="btn btn-outline btn-block btn-primary">查询</button>
						</div>
						</perm:hasPermission>
						<perm:hasPermission code="newgoods/insertGet">
					    <div class="col-md-1  col-sm-2 pull-right ">
							<a  onclick="clickInsertGet()" class="btn btn-block btn-outline btn-primary">添加</a>
					    </div>
					    </perm:hasPermission>
                    </div>
                </form>
				<table id="newgoods_table" data-action="${ctx}/newgoods/find" data-datatable="true"  class="footable table table-stripped toggle-arrow-tiny">
				  	<thead>
					  	<tr>
							<th data-sort-ignore="true"  data-title="title" >标题</th>
<!-- 							<th data-sort-ignore="true"  data-title="image" >图片</th> -->
							<th data-sort-ignore="true"  data-title="catName" >分类</th>
							<th data-sort-ignore="true"  data-title="brandName" >品牌</th>
<!-- 							<th data-sort-ignore="true"  data-title="status"  data-hide="phone,tablet">状态：0已通过，1待审核；2审核失败</th> -->
<!-- 							<th data-sort-ignore="true"  data-title="enable"  data-hide="phone,tablet">0：上架，1下架</th> -->
							<th  data-sort-ignore="true" data-title ="enable" data-hide="phone,tablet" data-type="enum" data-opt='{"0":"上架","1":"下架"}'>是否上架</th>
							<th data-sort-ignore="true"  data-title="browse"  data-hide="phone,tablet">浏览量</th>
							<th data-sort-ignore="true"  data-title="createDate" data-formater="yyyy-MM-dd" data-type="datetime" data-hide="phone,tablet">发布时间</th>
							<th  data-sort-ignore="true" data-title ="status" data-hide="phone,tablet" data-type="enum" data-opt='{"0":"已通过","1":"待审核","2":"审核失败"}'>状态</th>
							<th data-sort-ignore="true"  data-title="reason" >原因</th>
						  	<th data-sort-ignore="true"  data-crud="true" data-title='{"uid":"id"}' data-hide="phone">操作
			      			  <div style="display: none;" class="center hidden-phone">
<%-- 			      			  	  <perm:hasPermission code="newgoods/examine"> --%>
<%-- 					      			  		<button onclick="examineAjax(this)" data-url="${ctx}/newgoods/examine" style="margin-left:3px;" data-id=":uid" type="button" class="btn btn-primary btn-xs">提交审核</button> --%>
<%-- 								 </perm:hasPermission>			      			  	  --%>
										<div class="dropdown profile-element">
										<div id="div1" style="width:80px;height:27px;float:left;">
			      			  	 			<perm:hasPermission code="newgoods/update">
				                            <a data-toggle="dropdown" class="dropdown-toggle" href="#" aria-expanded="false">
				                                <span class="clear">
				                                <span class="btn btn-xs btn-outline btn-warning"><i class="fa fa-unlock-alt"></i>&nbsp;状态<b class="caret"></b></span>
				                                </span>
				                            </a>
				                            <ul class="dropdown-menu animated fadeInRight m-t-xs">
							      			  	 <perm:hasPermission code="newgoods/examine">
				                                	<li><a onclick="clickUpStatusSubmit(this)" data-id=":uid" type="button" class="btn  btn-xs">提交审核!</a></li>
				                                </perm:hasPermission>
				                                <li class="divider"></li>
							      			  	 <perm:hasPermission code="newgoods/update">
				                                	<li><a onclick="clickUpStatusOk(this)" data-id=":uid" type="button" class="btn  btn-xs">审核通过!</a></li>
				                                </perm:hasPermission>
				                                <li class="divider"></li>
							      			  	 <perm:hasPermission code="newgoods/update">
				                                	<li><a onclick="clickUpStatusError(this)" data-id=":uid" type="button" class="btn  btn-xs">审核失败!</a></li>
				                                </perm:hasPermission>
				                            </ul>
				                            </perm:hasPermission>
										 </div>
										<div id="div1" style="width:80px;height:27px;float:left;">
					      			  	 <perm:hasPermission code="newgoods/delete">
							      			 <button onclick="deleteAjax(this)" data-url="${ctx}/newgoods/delete" style="margin-left:3px;" data-id=":uid" type="button" class="btn btn-outline btn-danger btn-xs"><i class="fa fa-times"></i>&nbsp;删除</button>
										 </perm:hasPermission>
										</div>
										</div>
<%-- 								 <perm:hasPermission code="newgoods/examine">  --%>
<!-- 			      			  	 	<button onclick="examineAjax(this)" data-id=":uid" type="button" style="margin-right:5px" class="btn btn-primary btn-xs">提交审核</button>  -->
<%--  			      			  	 </perm:hasPermission> --%>
			      			  	 <perm:hasPermission code="newgoods/updateGet">
			      			  	 	<button onclick="clickUpdateGet(this)" data-id=":uid" type="button" style="margin-right:5px" class="btn btn-outline btn-info btn-xs"><i class="fa fa-pencil"></i>&nbsp;更新</button>
			      			  	 </perm:hasPermission>
			      			  	 <perm:hasPermission code="newgoods/findcomment">
			      			  	 	<button onclick="clickfindGet(this)" data-id=":uid" type="button" style="margin-right:5px" class="btn btn-outline btn-info btn-xs"><i class="fa fa-eye"></i>&nbsp;留言</button>
			      			  	 </perm:hasPermission>
							  </div> 
		      		      	</th>
					  	</tr>
				  	</thead>
				  	<tbody>
				  	</tbody>
			  	</table>
			  	<div class="row">
			  		<div class="col-md-6" class="pull-left" id="page_left_text"></div>
			  		<div class="col-md-6"  id="page_text"></div>
			  	</div>
			</div>
		</div>
		
	<script src="${ctx}/static/js/jquery.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/bootstrap.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/footable/footable.all.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/validate/jquery.validate.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/validate/messages_zh.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/webuploader/webuploader.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/summernote/summernote.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/summernote/summernote-zh-CN.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/chosen/chosen.jquery.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/layer/laydate/laydate.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/iCheck/icheck.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/plugins/laypage/laypage.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/switchery/switchery.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/eModal.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/cookie.js?v=?v=${static_version}"></script>
	<script src="${ctx}/static/common/custom-datatable.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/content.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/contabs.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/common/common.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/layer/layer.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/uploadify/jquery.uploadify.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/ueditor-1.4.3/ueditor.config.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/ueditor-1.4.3/ueditor.all.js?v=${static_version}"></script>
	
	<script>
		var ue;
		
		
		$(document).ready(function() {
			init_page_datatable();
		});
		var clickfindGet=function(me){
			location.href="${ctx}/newgoods/findcomment?id="+$(me).data("id");
		}
		
		var clickInsertGet=function(){
			eModal.ajax({
	   	        url: "${ctx}/newgoods/insertGet",
	   	        title:'添加新品发布',
	   	        loading:true,
	   	        subtitle: '',
	   	        buttons: [
	   	            {text: '保存',style:'info',close:false,click:function(){
		   	     		var images=[];
		   	 			$(".imageUploadify img").each(function(){
		   					images.push($(this).attr("src"));
		   				})
	   	 		    	var data={
								title:$("#title").val(),			
								content:ue.getContent(),					
								brandId:$("#brandId").val(),							
								catId:$("#catId").val(),							
								merchantId:$("#merchantId").val(),				
								image:images.toString(),							
								status:1,			
								enable:$("[name='enable']").is(":checked")?0:1,					
								browse:$("#browse").val(),							
								reason:$("#reason").val(),							
								createDate:$("#createDate").val(),							
								id:$("#id").val()
							}; 
		   	 		    	$.ajax({  
		   	 					url:'${ctx}/newgoods/add',  
								data: JSON.stringify(data),
								type: 'POST',
		   	 					dataType:'json',  
		   	 				    contentType:"application/json",
		   	 					success:function(response){
		   	 						if(response.code==0){
		   	 							eModal.close();
		   	 							$("#newgoods_table_search").click();
		   	 						}else{
		   	 						    $.confirm({cancelButton: "关   闭",title: '提示!',content: "修改公告错误!"});
		   	 						}
		   	 					}  
		   	 			    });
	   	            }},{text: '取消', style: 'danger', close: false, click:function(){
	   	            	eModal.close();
	   	            }}
	   	        ],
	   	    });
		}
		

		function examineAjax(me) {
			parent.layer.confirm('你确定提交审核吗？', {
		    btn: ['确定','取消'], //按钮
		    shade: false //不显示遮罩
		}, function(){
			$.ajax({  
					url:'${ctx}/newgoods/update',  
					data:{
					  status:1,							
					  id:$(me).data("id")
				    },   
				   type: 'POST',
					dataType:'json',  
			    }); 	
			  parent.layer.msg('提交审核成功', {icon: 6})
				$("#newgoods_table_search").click();	   
			
		}, function(){
		    parent.layer.msg('我再想想', {shift: 6});
		});
		}
		
		var clickUpdateGet=function(me){
			eModal.ajax({
	   	        url: "${ctx}/newgoods/updateGet?id="+$(me).data("id"),
	   	        title:'修改新品发布',
	   	        loading:true,
	   	        subtitle: '',
	   	        buttons: [
	   	            {text:'保存',style:'info',close:false,click:function(){
		   	     		var images=[];
		   	 			$(".imageUploadify img").each(function(){
		   					images.push($(this).attr("src"));
		   				})
	   	 		    		var data={
								title:$("#title").val(),							
								image:images.toString(),		
								content:ue.getContent(),						
								brandId:$("#brandId").val(),							
								catId:$("#catId").val(),							
								merchantId:$("#merchantId").val(),							
								status:$("#status").val(),			
								enable:$("[name='enable']").is(":checked")?0:1,						
								browse:$("#browse").val(),							
								reason:$("#reason").val(),							
								createDate:$("#createDate").val(),							
								id:$("#id").val()
							};
	   	 				$.ajax({  
	   	 					url:'${ctx}/newgoods/update',  
							data: JSON.stringify(data),
							type: 'POST',
	   	 					dataType:'json',  
	   	 				    contentType:"application/json",
	   	 					success:function(response){
	   	 						if(response.code==0){
	   	 							eModal.close();
	   	 							$("#newgoods_table_search").click();
	   	 						}else{
	   	 						    $.confirm({cancelButton: "关   闭",title: '提示!',content: "修改公告错误!"});
	   	 						}
	   	 					}  
	   	 			    }); 
	   	            }},{text: '取消', style: 'danger', close: false, click:function(){
	   	            	eModal.close();
	   	            }}
	   	        ],
	   	    });
		}



		$(function(){
		
			jQuery.searchFormInit();
		    
		    $.ajax({  
				url:'${ctx}/goodsCat/list',  		 					
				type: 'POST',
				dataType:'json',  
				success:function(response){
					if(response.code==0){
						var html=[];
						var data=response.data||[];
						for(var i=0;i<data.length;i++){
							html.push('<option value="'+data[i].id+'">'+data[i].name+'</option>');
						}
						$("#cat-select-select").append(html.join(""));
						$("#cat-select-select").trigger("chosen:updated");
					}
				 }  
		     });
			
			 $("#cat-select-select").chosen({width:'100%'}).change(function(event) {
				$("#cat-select-id").val($(event.target).val());
			 }); 
			 $.ajax({  
					url:'${ctx}/brand/list',  		 					
					type: 'POST',
					dataType:'json',  
					success:function(response){
						if(response.code==0){
							var html=[];
							var data=response.data||[];
							for(var i=0;i<data.length;i++){
								html.push('<option value="'+data[i].id+'">'+data[i].name+'</option>');
							}
							$("#brand-select-select").append(html.join(""));
							$("#brand-select-select").trigger("chosen:updated");
						}
					 }  
			     });
				
				 $("#brand-select-select").chosen({width:'100%'}).change(function(event) {
					$("#brand-select-id").val($(event.target).val());
				 });
		    
		});
				

		var clickUpStatusOk=function(me){
			$.ajax({
	   	        url: "${ctx}/newgoods/examine",
	   	        title:'审核成功',
	   	        loading:true,
	   	 		data:{						
					status:0,
					reason:"恭喜你，审核成功！",
					id:$(me).data("id")
				},   
				type: 'POST',
	   	    });
			  layer.msg('审核成功！', {icon: 1});
			$("#newgoods_table_search").click();
		}
		var clickUpStatusError=function(me){
			layer.prompt({
				  formType: 2,
				  title: '拒绝通过审核的原因，必须填写！'
				}, function(value){
					 $.ajax({
				   	        url: "${ctx}/newgoods/examine",
				   	        title:'审核失败',
				   	        loading:true,
				   	 		data:{				
				   	 			reason:value,
								status:2,		
								id:$(me).data("id")
							},   
							type: 'POST',
				   	    });
				  layer.msg('审核失败！', {icon: 5});
					$("#newgoods_table_search").click();
				});
			  layer.close(index);
		}

		var clickUpStatusSubmit=function(me){
			$.ajax({
	   	        url: "${ctx}/newgoods/examine",
	   	        title:'提交审核',
	   	        loading:true,
	   	 		data:{						
					status:1,		
	   	 			reason:"待审核。",		
					id:$(me).data("id")
				},   
				type: 'POST',
	   	    });
			  layer.msg('待审核状态！', {icon: 1});
			$("#newgoods_table_search").click();
		}
		
		
		
		
	</script>
	
	</body>
</html>